app.controller('bpmdeployController', ['$scope', 'httpWrapService', 'dialogs', '$state', '$stateParams',
                        '$location', '$anchorScroll','dialogs','FileUploader','validationService',
            function ($scope, httpWrapService, dialogs, $state, $stateParams, $location, $anchorScroll, dialogs, FileUploader,validationService) {

    //$scope.save = function () {
    //    httpWrapService.defaultSave( 'system/group/' + $scope.type + '.do',{
    //        entity : $scope.entity,
    //        roles : roles
    //    }, $scope).then(function (res) {
    //        $state.go('app.bpm.manager.definition');
    //    });
    //}

    $scope.cancel = function () {
        // 后退到列表页面
        $state.go('app.bpm.manager.definition');
    }

    var uploader = $scope.uploader = new FileUploader({
        url: 'bpm/deployment/deploy.do',
        headers : {
            'Accept': 'application/json, text/plain, */*'
        }
    });

    // FILTERS
    //uploader.filters.push({
    //    name: 'customFilter',
    //    fn: function(item /*{File|FileLikeObject}*/, options) {
    //        return this.queue.length < 10;
    //    }
    //});

    // CALLBACKS

    //uploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/, filter, options) {
    //    console.info('onWhenAddingFileFailed', item, filter, options);
    //};
    //uploader.onAfterAddingFile = function(fileItem) {
    //    console.info('onAfterAddingFile', fileItem);
    //};
    //uploader.onAfterAddingAll = function(addedFileItems) {
    //    console.info('onAfterAddingAll', addedFileItems);
    //};
    //uploader.onBeforeUploadItem = function(item) {
    //    console.info('onBeforeUploadItem', item);
    //};
    //uploader.onProgressItem = function(fileItem, progress) {
    //    console.info('onProgressItem', fileItem, progress);
    //};
    //uploader.onProgressAll = function(progress) {
    //    console.info('onProgressAll', progress);
    //};
    uploader.onSuccessItem = function(fileItem, response, status, headers) {
        if(!response.success) {
            console.info('上传处理失败！');
            dialogs.error('错误', '['+fileItem.file.name+'] ' + response.msg, {size: 'md'});
            fileItem.remove();
        }
        //console.info('onSuccessItem', fileItem, response, status, headers);
    };
    //uploader.onErrorItem = function(fileItem, response, status, headers) {
    //    console.info('onErrorItem', fileItem, response, status, headers);
    //};
    //uploader.onCancelItem = function(fileItem, response, status, headers) {
    //    console.info('onCancelItem', fileItem, response, status, headers);
    //};
    //uploader.onCompleteItem = function(fileItem, response, status, headers) {
    //    console.info('onCompleteItem', fileItem, response, status, headers);
    //};
    //uploader.onCompleteAll = function() {
    //    console.info('onCompleteAll');
    //};
}]);
